function(_add_interfaces)
  set(LLVM_TARGET_DEFINITIONS TMTensorInterfaces.td)
  mlir_tablegen(TMTensorOpInterfaces.h.inc -gen-op-interface-decls)
  mlir_tablegen(TMTensorOpInterfaces.cpp.inc -gen-op-interface-defs)
  mlir_tablegen(TMTensorTypeInterfaces.h.inc -gen-type-interface-decls)
  mlir_tablegen(TMTensorTypeInterfaces.cpp.inc -gen-type-interface-defs)
  add_public_tablegen_target(TorchMLIRTMTensorInterfacesIncGen)
  add_dependencies(TorchMLIRTMTensorOpsIncGen TorchMLIRTMTensorInterfacesIncGen)
endfunction()

function(_add_scalar_loop_op_interface)
  set(LLVM_TARGET_DEFINITIONS ScalarLoopOpInterface.td)
  mlir_tablegen(ScalarLoopOpInterface.h.inc -gen-op-interface-decls)
  mlir_tablegen(ScalarLoopOpInterface.cpp.inc -gen-op-interface-defs)
  add_public_tablegen_target(TorchMLIRTMTensorScalarLoopOpInterfaceIncGen)
  add_dependencies(TorchMLIRTMTensorOpsIncGen TorchMLIRTMTensorScalarLoopOpInterfaceIncGen)
endfunction()

function(_add_dialect)
  set(LLVM_TARGET_DEFINITIONS TMTensorOps.td)
  mlir_tablegen(TMTensorOps.h.inc -gen-op-decls)
  mlir_tablegen(TMTensorOps.cpp.inc -gen-op-defs)
  mlir_tablegen(TMTensorTypes.h.inc -gen-typedef-decls)
  mlir_tablegen(TMTensorTypes.cpp.inc -gen-typedef-defs)
  mlir_tablegen(TMTensorDialect.h.inc -gen-dialect-decls -dialect=tm_tensor)
  mlir_tablegen(TMTensorDialect.cpp.inc -gen-dialect-defs -dialect=tm_tensor)
  add_public_tablegen_target(TorchMLIRTMTensorOpsIncGen)
  add_dependencies(mlir-headers TorchMLIRTMTensorOpsIncGen)
endfunction()

_add_dialect()
_add_interfaces()
_add_scalar_loop_op_interface()
